package pl.leader100.rest;

import java.util.List;

import javax.ws.rs.GET;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Request;
import javax.ws.rs.core.UriInfo;

import pl.leader100.rest.data.Doc;
import pl.leader100.rest.data.DocDao;

	// The class registers its methods for the HTTP GET request using the @GET annotation. 
	// Using the @Produces annotation, it defines that it can deliver several MIME types,
	// text, XML and HTML. 

	// The browser requests per default the HTML MIME type.

	//Sets the path to base URL + /hello
	
	public class ListDoc {
		@Context
		UriInfo uriInfo;
		@Context
		Request request;
		
		String role;
		String date;
		String locale;
		String year = "2011/2012";
		String course = "junior_leader_r1";
		
			
		public ListDoc(UriInfo uriInfo, Request request, String role, String date, String locale) {
			this.uriInfo = uriInfo;
			this.request = request;
			this.role = role;
			this.date = date;
			this.locale= locale;
		}
		
		public ListDoc(UriInfo uriInfo, Request request, String role, String date, String locale, String year, String course) {
			this.uriInfo = uriInfo;
			this.request = request;
			this.role = role;
			this.date = date;
			this.locale= locale;
			this.year=year;
			this.course = course;
		}


		
		// This method is called if TEXT_PLAIN is request
		@GET
		@Produces(MediaType.TEXT_PLAIN)
		public String sayPlainTextHello() {
			return "no way";
		}

		//Application integration 		
		@GET
		@Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
		public List<Doc> getDoc() {
			List<Doc> docs = DocDao.GetInstance().getDocsOld(role, date, locale, year, course);
			if(docs==null)
				throw new RuntimeException("Get: Doc with " + role +" "+date+" "+locale +  " not found");
			return docs;
		}
		
		// For the browser
		@GET
		@Produces(MediaType.TEXT_XML)
		public List<Doc> getTodoHTML() {
			List<Doc> docs = DocDao.GetInstance().getDocsOld(role, date, locale, year, course);
			if(docs==null)
				throw new RuntimeException("Get: Doc with " + role +" "+date+" "+locale +  " not found");
			return docs;
		}
		
		

}
